#ifndef FORMAT_H_
#define FORMAT_H_

/*
Copyright (C) 2011 Salil Bhagurkar

This file is part of illusion

illusion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

illusion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with illusion.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <kernel/types.h>

//typedef char* va_list;
//#define va_start(ap,v)(ap=(va_list)&v+sizeof(v))
//#define va_arg(ap,t) *(t*)((ap +=sizeof(t))-sizeof(t))
//#define va_end(ap) ( ap = (va_list)0)

typedef unsigned size_t;


typedef char *va_list;
typedef int (*fnptr_t)(unsigned int c);


#define	STACKITEM	int
#define	VA_SIZE(TYPE)					\
	((sizeof(TYPE) + sizeof(STACKITEM) - 1)	\
		& ~(sizeof(STACKITEM) - 1))
#define	va_start(AP, LASTARG)	\
	(AP=((va_list)&(LASTARG) + VA_SIZE(LASTARG)))

#define va_end(AP)


#define va_arg(AP, TYPE)	\
	(AP += VA_SIZE(TYPE), *((TYPE *)(AP - VA_SIZE(TYPE))))


uint_t format_string_va(char *buffer, uint_t buffer_size,
		char *fmt, va_list list);
uint_t format_string(char *buffer, uint_t buffer_size, char *fmt, ...);
uint_t dec2string(char *_str);
uint_t hex2string(char *_str);

#endif /* FORMAT_H_ */
